package band.wukong.practice.springboot.spring4.advanced.scheduling;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wukong(wukonggg@139.com)
 */
@Component
public class ScheduledTaskService {

    private static final Logger logger = LoggerFactory.getLogger(ScheduledTaskService.class);

    private static final String PATTERN = "HH:mm:ss";

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTimeOnFixedRate() {
        logger.info("每隔五秒执行一次：" + new SimpleDateFormat(PATTERN).format(new Date()));
    }

    @Scheduled(cron = "0/5 * * * * *")
    public void reportCurrentTimeOnCron() {
        logger.info("在指定时间 " + new SimpleDateFormat(PATTERN).format(new Date()) + " 执行");
    }

}
